package boot.spring.controller;

import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

import java.time.Duration;
import java.time.LocalTime;

@RestController
public class FluxController {
    /**
     * 实时更新当前时间（每秒推送一次）
     */
    @GetMapping(value = "/stream/time", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    public Flux<String> streamTime() {
        return Flux.interval(Duration.ofSeconds(1)) // 每隔 1 秒生成一个事件
                .map(sequence -> "Current Time: " + LocalTime.now());
    }
}
